package com.fc.app.fcapp.pages.jsondata;

import android.util.Log;

import com.alibaba.fastjson.JSON;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by fc on 2017/11/23.
 */

public class HttpMethods {


    public  static List<PkgMsg>pkgMsgs = new ArrayList<>();

    public static List<PkgMsg> getPkgMsgs() {

        for (int i =0;i<2;i++){
            PkgMsg pkgMsg =new PkgMsg();
            pkgMsg.productID = "CC_Appstore";
            pkgMsg.x1 = "CC_Setting";
            pkgMsg.x2 = "CC_Moive";
            pkgMsg.x3 = "CC_Advertisement";
            pkgMsg.pkg_name = "com.tianci.appstore";
            pkgMsg.pkg_source = "CC_HomePage6.0###广东省深圳市宝安区石岩街道  创维科技工业园 科技大楼10楼  创维集团RGB软件研究院";
            pkgMsg.pkg_vercode = "CC_TCVideo6.0########123456789\n123456789\n123456789\n123456789\n123456789\n123456789\n123456789\n123456789\n123456789\n";
            pkgMsg.pkg_vername ="CC_Mall#######测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据adcd"+
                    "#######测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据adcd"+
                    "#######测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据adcd"+
                    "#######测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据adcd"+
                    "#######测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据adcd"+
                    "#######测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据abcd测试数据adcd";


            pkgMsgs.add(pkgMsg);
        }

        return pkgMsgs;
    }

    public synchronized static void postData(List<PkgMsg>pkgMsgs) {
        StringBuilder submitStr = new StringBuilder();
        for (PkgMsg p:pkgMsgs){
            SubmitData submitData = new SubmitData();
            submitData.pkg = com.alibaba.fastjson.JSONObject.parseObject(com.alibaba.fastjson.JSONObject.toJSONString(p), Map.class);

            submitStr.append(com.alibaba.fastjson.JSONObject.toJSONString(submitData)).append("\n");
        }
        PkgMsg pkgMsg = pkgMsgs.get(0);
        Log.i("submitStr ", "\n"+"-------------------------------start");
        try {
            HashMap pkgMsg1;
            pkgMsg1 = (HashMap) com.alibaba.fastjson.JSONObject.parseObject(com.alibaba.fastjson.JSONObject.toJSONString(pkgMsg),Map.class);
            PkgMsg pkgMsg2 = JSON.parseObject(com.alibaba.fastjson.JSONObject.toJSONString(pkgMsg1),PkgMsg.class);

            String s = com.alibaba.fastjson.JSONObject.toJSONString(pkgMsg);
            String s1 = com.alibaba.fastjson.JSONObject.toJSONString(pkgMsg1);
            String s2 = com.alibaba.fastjson.JSONObject.toJSONString(pkgMsg2);


            Log.i("submitStr", "pkgMsg:  " +com.alibaba.fastjson.JSONObject.toJSONString(pkgMsg));
            Log.i("submitStr", "pkgMsg1: " +com.alibaba.fastjson.JSONObject.toJSONString(pkgMsg1));
            Log.i("submitStr", "pkgMsg2: " +com.alibaba.fastjson.JSONObject.toJSONString(pkgMsg2));

            Log.i("submitStr ", "string:  " +s.equals(s1));
            Log.i("submitStr","obj:     "+ s.equals(s2));


        } catch (Exception e) {
            e.printStackTrace();
            Log.i("submitStr ", e.toString());
        }

    }
}
